package LeetCode;

import java.util.Collections;
import java.util.HashSet;

public class LC_676_ImplementMagicDictionary {

    public static void main(String[] args) {

    }

    class MagicDictionary {

        private HashSet<String> set;

        public MagicDictionary() {
            set = new HashSet<>();
        }

        public void buildDict(String[] dict) {
            set.clear();
            Collections.addAll(set, dict);
        }

        public boolean search(String word) {
            char[] w = word.toCharArray();
            for (int i = 0; i < w.length; i++) {
                char temp = w[i];
                for (char j = 'a'; j <= 'z'; j++) {
                    if (temp != j) {
                        w[i] = j;
                        if (set.contains(new String(w))) {
                            return true;
                        }
                    }
                }
                w[i] = temp;
            }
            return false;
        }
    }

}